﻿using System;
using System.Data;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;
using MediaPortal.Player;
using System.Data.SQLite;

namespace SimTV
{
    public class SimTV : GUIWindow, ISetupForm
    {
        //SimTV Data Members
        #region DataMemberes

        private int WindowID = 5678;                  //Unique Window ID
        private string skinPath = "SimTV.xml";         //Path To Skin XML

        //Dynamic GUI Elements
        GUILabelControl mylabel;

        #endregion

        //Basic Plugin Setup Methods
        #region ISetupForm Members

        public override bool Init()
        {
            //Add An Action Handler So This Plugin Can Respond To User Actions
            GUIWindowManager.OnNewAction += new OnActionHandler(this.ActionHandler);
            return Load(GUIGraphicsContext.Skin + @"\" + skinPath);

            //Render Dynamic GUI Elements
            //AllocResources();
        }

        //Returns The Name Of The Plugin - "SimTV"
        public string PluginName()
        {
            return "SimTV";
        }

        //Returns A Description Of The Plugin
        public string Description()
        {
            return "Allows You To Simulate TV Stations Using Your Media Library";
        }

        //Returns Plugin Author - "SammyK"
        public string Author()
        {
            return "SammyK";
        }

        //Show The Setup Dialog
        public void ShowPlugin()
        {
            MessageBox.Show("TODO...");
        }

        //Set If The Plugin Can Be Enabled / Disabled
        public bool CanEnable()
        {
            return true;
        }

        //Get Window-ID
        public int GetWindowId()
        {
            return WindowID;
        }

        //Set If The Plugin Should Be Enabled By Default
        public bool DefaultEnabled()
        {
            return true;
        }

        //Set If The Plugin Has A Setup Screen
        public bool HasSetup()
        {
            return true;
        }

        //Configuration For Showing The Plugin In Media Portal Home Screen
        public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
        {
            strButtonText = PluginName();           //Text For Home Screen Button
            strButtonImage = String.Empty;          //Image For Home Screen Button
            strButtonImageFocus = String.Empty;     //Focus Image For Home Screen Button
            strPictureImage = String.Empty;         //Sub Picture For Home Screen Button
            return true;
        }

        //Returns The Windows ID And Indicates This Is A Window Plugin
        public override int GetID
        {
            get
            {
                return WindowID;
            }
            set
            {

            }
        }

        #endregion

        //SimTV Methods
        #region Methods

        //Handle User Actions
        void ActionHandler(MediaPortal.GUI.Library.Action action)
        {

        }

        #endregion

        //SimTV Dynamic GUI Elements
        #region DynamicGUIElements

        public override void AllocResources()
        {
            base.AllocResources();
            
            string dbPath = "C:/ProgramData/Team MediaPortal/MediaPortal/database";
            string queryString = "SELECT Pretty_Name FROM Online_Series WHERE ID='72173'";
            DataTable queryResults = SimTV_DBHelpers.ExecuteSQLQuery(dbPath, queryString);
            string queryStingResult = queryResults.Rows[0].ItemArray[0].ToString();

            mylabel = new GUILabelControl(153557383, 101, 256, 256, 100, 100, string.Empty, queryStingResult, 0xFFFFFFFF, GUIControl.Alignment.ALIGN_CENTER, GUIControl.VAlignment.ALIGN_MIDDLE, false, 20, 20, 0xFFFFFFFF);
            mylabel.AllocResources();
        }

        public override void Render(float timePassed)
        {
            base.Render(timePassed);
            mylabel.Render(timePassed);
        }

        #endregion
    }
}
